<template>
  <div class="right">
    <div class="grzx">
      <h3 class="hh-sy">个人中心首页</h3>
      <div class="grzl">
        <div class="top af">
          <img :src="'https://exam.zhonghaiqihang.com/'+title.gr.avatar" width="180px" height="180px" class="lf1">
          <div class="lf2">
            <h4>{{this.title.gr.username}}</h4>
            <p class="p1">性 别：<span>{{this.title.gr.gender==1?'男':''}}{{this.title.gr.gender==2?'女':''}}{{this.title.gr.gender==''?'暂未设置':''}}{{this.title.gr.gender==null?'暂未设置':''}}</span></p>
            <p class="p2">用户账号：<span>{{this.title.gr.name}}</span></p>
          </div>
          <a href="/PersonalCenter/Modify" class="lf3">修改资料</a>
        </div>
        <ul class="bt af">
          <li class="li1">
            <p class="p1 af"><span></span></p>
            <p class="p2">注册时间</p>
            <p class="p3">{{this.title.gr.createtime}}</p>
          </li>
          <li class="li2">
            <p class="p1 af"><span></span><a href="/PersonalCenter/Modify?name=phone#sjhm"></a></p>
            <p class="p2">手机号</p>
            <p class="p3">{{this.title.gr.mobile}}</p>
            <p class="p3">{{this.title.gr.mobileone}}</p>
            <p class="p3">{{this.title.gr.mobiletwo}}</p>
          </li>
          <li class="li3">
            <p class="p1 af"><span></span><a href="/PersonalCenter/Modify?name=email#dzyx"></a></p>
            <p class="p2">电子邮箱</p>
            <p class="p3">{{this.title.gr.email}}</p>
          </li>
          <li class="li4">
            <p class="p1 af"><span></span><a href="/PersonalCenter/Modify"></a></p>
            <p class="p2">身份证</p>
            <p class="p3">{{this.title.gr.idcard}}</p>
          </li>
        </ul>
      </div>
    </div>
    </div>
  </div>
</template>

<script>
  import axios from 'axios';
  import $ from 'jquery';
  export default {
    props: ['foobar'],
    data () {
      return {
        title:null
      }
    },
    async asyncData ({req,params}){
      let a = req.headers.cookie;
      let cookie = '';
      if(a.indexOf('userinfoRes')!=-1){
        let b = a.split('userinfoRes=');
        let c = b[1].split(';');
        cookie = c[0];
      }
      let gr = await axios.get(`https://exam.zhonghaiqihang.com/PInterface/UserCenter/userCenterIndexData?userid=`+cookie);
      let nh = await axios.get(`https://exam.zhonghaiqihang.com/PInterface/Header/headerData`);
      let data  = {nav:nh.data,id:cookie,gr:gr.data};
      return { title: data}
    },
   mounted:function(){
    $('.tbnava1').addClass('select');
    function setCookie(cname,cvalue,exdays)
    {
      var d = new Date();
      d.setTime(d.getTime()+(exdays*24*60*60*1000));
      var expires = "expires="+d.toGMTString();
      document.cookie = cname + "=" + cvalue + "; " + expires;
    }
     if(this.title.gr == 'go_signin'){
       this.$router.push('/Login');
       setCookie('userinfoRes','',-1);
     }else if(this.title.gr == 'userid_error'){
       this.$router.push('/Login');
       setCookie('userinfoRes','',-1);
     }else if(this.title.gr == 'userinfo_is_null'){
       this.$router.push('/Login');
       setCookie('userinfoRes','',-1);
     }else if(this.title.gr == 'userinfo_banuse'){
       this.$router.push('/Login');
       setCookie('userinfoRes','',-1);
     }
     else if(this.title.gr == 'serviceid_is_null'){
       window.open('/Mall',_self);
     } else if(this.title.gr == 'serviceid_error'){
       window.open('/Mall',_self);
     }else if(this.title.gr == 'serviceinfo_is_null'){
       window.open('/Mall',_self);
     }else if(this.title.gr == 'serviceinfo_banuse'){
       window.open('/Mall',_self);
     }
    // if(this.title.gj == 'go_signin'){
    //   this.$router.push('/Login');
    //   setCookie('userinfoRes','',-1);
    // }else if(this.title.gj == 'userid_error'){
    //   this.$router.push('/Login');
    //   setCookie('userinfoRes','',-1);
    // }else if(this.title.gj == 'userinfo_is_null'){
    //   this.$router.push('/Login');
    //   setCookie('userinfoRes','',-1);
    // }else if(this.title.gj == 'userinfo_banuse'){
    //   this.$router.push('/Login');
    //   setCookie('userinfoRes','',-1);
    // }
    // else if(this.title.gj == 'serviceid_is_null'){
    //   window.open('/Mall',_self);
    // } else if(this.title.gj == 'serviceid_error'){
    //   window.open('/Mall',_self);
    // }else if(this.title.gj == 'serviceinfo_is_null'){
    //   window.open('/Mall',_self);
    // }else if(this.title.gj == 'serviceinfo_banuse'){
    //   window.open('/Mall',_self);
    // }





    $(document).ready(function(){
      $('.hh-xgzl .div .bj').click(function(){
        $(this).toggleClass('select');
        $(this).siblings('strong').toggleClass('select');
        $(this).parent().siblings('.ycd').toggleClass('select');
        $(this).parent().siblings('.tx').toggleClass('select');
        if($(this).text()=='编辑'){
          $(this).html('展开<i></i>');
        }else if($(this).text()=='展开'){
          $(this).html('编辑<i></i>');
        }
      });
      $('.hh-zssc .sct li').hover(function(){
        $(this).siblings().removeClass('select');
        $(this).addClass('select');
      });

      $('.hh-xgzl .div .bc').click(function(){
        $(this).parent().parent().children('strong').removeClass('select');
      });
    })
  },
   mothods:{
     tc:function(e1,e2,e3){
       var d = new Date();
       d.setTime(d.getTime()+(e3*24*60*60*1000));
       var expires = "expires="+d.toGMTString();
       document.cookie = e1 + "=" + e2 + "; " + expires;
       this.$router.push('/');
     }
   }
  }
</script>

<style>

</style>
